package cn.com.chengmandian.bike.controller;


import cn.com.chengmandian.agent.utils.AuthUtil;
import cn.com.chengmandian.bike.dto.FaultSoftwareAddForm;
import cn.com.chengmandian.bike.dto.FaultSoftwareDto;
import cn.com.chengmandian.bike.log.ActionLog;
import cn.com.chengmandian.bike.model.EbFaultSoftware;
import cn.com.chengmandian.bike.model.vo.FaultSoftwareVo;
import cn.com.chengmandian.bike.service.IEbFaultSoftwareService;
import cn.com.chengmandian.core.db.pojo.PageData;
import cn.com.chengmandian.core.web.pojo.AgentInfo;
import cn.com.chengmandian.core.web.pojo.AgentUser;
import cn.com.chengmandian.core.web.pojo.AjaxResult;
import cn.com.chengmandian.core.web.utils.LocalMapUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 电单车运营-软件问题反馈 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2021-12-23
 */
@Api(tags = "软件问题反馈相关接口")
@RestController
@RequestMapping("/fault/software")
public class EbFaultSoftwareController {
    @Autowired
    private IEbFaultSoftwareService faultSoftwareService;

    @ApiOperation("新增问题反馈")
    @PostMapping("/add")
    @ActionLog(name="新增问题反馈",description = "'参数：' + #faultSoftwareAddForm")
    public AjaxResult add(@RequestBody FaultSoftwareAddForm faultSoftwareAddForm) {
        AgentInfo agentInfo = LocalMapUtil.getAgentInfo();
        Assert.notNull(agentInfo.getAreaId(), "缺少运营区ID");
        faultSoftwareAddForm.setAreaId(agentInfo.getAreaId());
        AgentUser agentUser = AuthUtil.getAgentUser();
        faultSoftwareService.addSoftware(faultSoftwareAddForm, agentUser);
        return AjaxResult.success("提交成功，感谢您的反馈!");
    }

    @ApiOperation("分页")
    @GetMapping("/pages")
    public AjaxResult<PageData<FaultSoftwareVo>> pages(FaultSoftwareDto dto) {
        AgentInfo agentInfo = LocalMapUtil.getAgentInfo();
        Assert.notNull(agentInfo.getAreaId(), "缺少运营区ID");
        dto.setAreaId(agentInfo.getAreaId());
        return AjaxResult.success(PageData.build(faultSoftwareService.getPage(dto, AuthUtil.getAgentUser().getId())));
    }

    @ApiOperation("详情")
    @GetMapping("/detail/{id}")
    public AjaxResult<EbFaultSoftware> detail(@PathVariable("id") Integer id){
        return AjaxResult.success(faultSoftwareService.getById(id));
    }
}
